// 导入需要用到的包

import { useEffect } from "react";

import { useDispatch, useSelector } from "react-redux";

// 创建 useInitialState 函数 自定义钩子函数

const useInitialState = (action: any, stateName: any) => {
  const dispatch = useDispatch();
  const state = useSelector((state: any) => state[stateName]);

  useEffect(() => {
    dispatch(action());
  }, [dispatch, action]);

  return state;
};
export { useInitialState };
